<style>
body{margin:0;padding:10px;}
.function {
	background:#acf;
	display:inline;
	padding:6px;
	margin:5px;
	position:relative;
	border-left:14px solid transparent;
}
.function form { margin:0; padding:0; display:inline; }
.function .argument { font:italic normal 18px 'Times New Roman'; margin-right:5px; }
.function input { font:normal normal 12px sans-serif; margin-right:2px; }
div.function:hover {border-left:14px solid #f55;}
div.function:hover .title {visibility:visible; background-color:red;}
</style>

<script>
var $=function(x){return document.getElementById(x)};

var coalesce=function(){
	for(var i=0;i<arguments.length;++i)
		if(arguments[i]!==null)
			return arguments[i];
};

var dict=[];

var expr=(function(){
	var f_repl=function(_,x){return "\","+x+",\""};
	return function(x){
		x=x.replace(/\\/g,"\\\\").replace(/"/g,"\"");
		x=x.replace(/\$(\w+)/g, f_repl);
		x=x.replace(/\${([^}]+)}/g, f_repl);
		return '["'+x+'"]';
	}
})();

var form_submit=function(oF,f){
	var i, x, args=[];
	for(i=0;x=oF.elements[i];++i)
		if(x.name)
			args[args.length]=x.value;
	f.apply(oF, args);
};

Object.prototype.toString=function(){
	var i, v, out=[];
	for(i in this)
		out[out.length]=i+":"+this[i];
	return "{"+out.join(",")+"}";
};

var __function_to_string=Function.prototype.toString;
Function.prototype.toString=function(){
	var source=__function_to_string.apply(this);
	if(!this.dict_id)
		dict[this.dict_id=dict.length]=this;
	var _onsubmit=eval(expr("try{form_submit(this,dict[${this.dict_id}])}catch(e){alert(e)}return!1"));

	var name=this.name ? this.name : ( source.match(/\"([^ ,\.\"]+)/) ? RegExp.$1 : "run" );

	var inputs=source.match(/\(([^\)]*)\)/)[1].replace(/([^,]+)/g,function(x){
		return "<span class='argument'>"+x+":</span><input type='text' name='"+x+"' size='"+(5+2*x.length)+"'>";
	});
	return eval(expr("\
<div class='function'>\
	<form action='?' onsubmit='$_onsubmit'>\
		${inputs}<input type='submit' value='$name'>\
	</form>\
</div>"));
};

Array.prototype.toString=function(){
	var i, out=[];
	for(i=0;i<this.length;++i)
		out[out.length]=this[i].toString();
	return out.join("");
};


var trace=(function(){
	var oOut, timer;
	return function(x){
		if(!oOut){
			oOut=document.body.appendChild(document.createElement("textarea"));
			oOut.style.cssText="opacity:0.9;left:0;position:absolute;bottom:0;width:100%;height:200px;color:#ccc;background:#000;font:normal normal 11px Courier New";
		}
		oOut.value+=x+"\n";
		oOut.style.display="block";
//		if(timer)window.clearTimeout(timer);
//		timer=window.setTimeout(function(){oOut.style.display="none"},5000);
	}
})();

var page=[
	function(x){
		trace("hello, "+x)
	},
	function Send(){
		var r = new XMLHttpRequest();
		r.open('get', '/app/', false);
		r.send(null);
		trace(r.getAllResponseHeaders());
	}
];


document.write(page.toString());

</script>








